package com.strutsDeom;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.util.Map;

public class LoginAction extends ActionSupport  {
    //用户输入的姓名
    private String name="";

    //用户密码
    private String userPassWord;

    public String getUserPassWord() {
        return userPassWord;
    }

    public void setUserPassWord(String userPassWord) {
        this.userPassWord = userPassWord;
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public void validate(){
        if(this.getName()==null && this.getName().length()==0){
            addFieldError("name","用户名不能为空");
        }
        if(this.getUserPassWord()==null && this.getUserPassWord().length()==0){
            addFieldError("password","密码不能为空");
        }
    }
    public String execute(){
        if("jason".equals(name) && "2010".equals(userPassWord)){
            //获取session
            Map<String,Object> session=null;
            session= ActionContext.getContext().getSession();
            session.put("CURRENT_USER",name);
            return Action.SUCCESS;
        }else {
            //登陆失败，返回error
            return Action.ERROR;
        }
    }
}
